package game.graphics.effects;

import static org.lwjgl.opengl.GL11.*;
import game.camera.Camera;
import helpers.Circle;
import application.Configuration;
import application.Window;

/**
 * Effect, which represents explosion of gunshot when it collides
 * with another object.
 * 
 * @author Tomas Zima
 */
public class GunshotExplosionEffect implements IGraphicEffect
{
	/**
	 * Constructor.
	 * Saves beginning coordinates of a gunshot.
	 * 
	 * @param x
	 * @param y
	 */
	public GunshotExplosionEffect(int x, int y)
	{
		this.positionX = x;
		this.positionY = y;
	}
	
	/**
	 * Updates position of gunshot.
	 */
	@Override
	public void update(long deltaTime)
	{
		/*
		 * Move to correct way.
		 */
		if (way)
		{
			size += (deltaTime * 0.05f);
		}
		else
		{
			size -= (deltaTime * 0.05f);
		}
		
		/*
		 * Reverse way after achieving some size.
		 */
		if (size >= 15)
		{
			way = false;
		}
		
		/*
		 * Destroy after finishing whole animation.
		 */
		if (size < 0 && way == false)
		{
			done = true;
		}
	}

	/**
	 * Redraw an effect.
	 */
	@Override
	public void redraw(int cameraX, int cameraY)
	{
		// TODO: fix bug with color
		glDisable(GL_TEXTURE_2D);
		
		glColor3f(0.5f, 0.0f, 0.0f);
		Circle.drawFilled(
				Camera.getPositionX(positionX, cameraX),
				Camera.getPositionY(positionY, cameraY),
				(int) size,
				30);
		
		glEnable(GL_TEXTURE_2D);
	}

	/**
	 * Checks if animation is done and effect should be
	 * removed.
	 */
	@Override
	public boolean isDone()
	{
		return done;
	}
	
	// Set at begin
	private int positionX;
	private int positionY;
	private boolean way = true;
	
	// Modified runtime
	private float size;
	private boolean done = false;
}
